#ifndef _DICOM_STORAGE_STREAM_H_
#define _DICOM_STORAGE_STREAM_H_

#include "gwbase/base/status.h"
#include "gwbase/base/file_ops.h"

namespace dicom {

class ReaderStream {
 public:
  ReaderStream() {};
  virtual ~ReaderStream() {};

  virtual int Read(void* buf, size_t len) = 0;
  virtual void Close() = 0;
};

class WriterStream {
 public:
  WriterStream() {}
  virtual ~WriterStream() {}

  virtual int Write(const void* buf, size_t len) = 0;
  virtual int Finalize() = 0;
  virtual void Close() = 0;
};

class FileReader : public ReaderStream {
 public:
  FileReader() {}
  virtual ~FileReader() { Close(); }

  Status Open(const std::string& path);
  int Read(void* buf, size_t len);
  void Close();

 private:
  SequentialFilePtr in_file_;
};

class FileWriter : public WriterStream {
 public:
  FileWriter() {}
  virtual ~FileWriter() { Close(); }

  Status Open(const std::string& path);
  int Write(const void* buf, size_t len);
  int Finalize();
  void Close();

 private:
  WritableFilePtr out_file_;
};

class NullWriter : public WriterStream {
 public:
  NullWriter() {}
  virtual ~NullWriter() { Close(); }

  int Write(const void* buf, size_t len) { return static_cast<int>(len); }
  int Finalize() { return 0; }
  void Close() {}
};
}

#endif  // _DICOM_STORAGE_STREAM_H_
